#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <wait.h>
#include <stdlib.h>

int main(int argc, char const *argv[])
{
    pid_t pid = fork();

    if( pid > 0 )
    {
        while(1)
        {
            printf( "parent proccess running\n" );
            sleep(1);

            int status;
            //if( wait( NULL ) )
            //if( wait( &status ) )
            if( waitpid( -1, &status, WNOHANG | WUNTRACED | WCONTINUED ))
            {
                perror( "wait status" );
            }

            if( WIFEXITED( status ) )
            {
                printf( "status = %d\n", WEXITSTATUS( status ) );
            }
            else if( WIFSIGNALED( status ) )
            {
                printf( "sig = %d\n", WTERMSIG( status ) );
            }
            else if( WIFSTOPPED( status ) )
            {
                printf( "stop sig = %d\n", WSTOPSIG( status ) );
            }
        }
    }
    else if( pid == 0 )
    {
        int i;
        for( i = 0; i < 5; ++i )
        {
            printf( "child proccess running %d\n", i);
            sleep(1);
        }
        printf( "child proccess end\n" );
        exit( 88 );
    }

    return 0;
}

/*
    命令：
    ps aux | grep a.out
    killall -9 a.out
*/